package com.ljt.business.controller;


import com.ljt.business.entity.Consumer;
import com.ljt.business.service.ConsumerService;
import com.ljt.response.Result;
import com.ljt.system.entity.Health;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljt
 * @since 2021-07-05
 */
@RestController
@RequestMapping("/business/consumer")
@CrossOrigin
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;

    @ApiOperation(value="需求方信息",notes = "查询所有需求方信息")
    @GetMapping("/queryConsumerCount")
    public Result queryConsumerCount(){
        List<Consumer> consumer=consumerService.queryConsumerCount();
        return Result.ok().data("consumer",consumer);
    }

    @ApiOperation(value="添加需求方信息",notes = "添加需求方信息")
    @GetMapping("/saveConsumer")
    public Result saveConsumer(Consumer consumer){
        boolean i=consumerService.save(consumer);
        if(i){
            return Result.ok().data("consumer",consumer);
        }else{
            return Result.error();
        }

    }

    @ApiOperation(value="删除需求方信息",notes = "删除需求方信息")
    @GetMapping("/deleteConsumer")
    public Result deleteConsumer(int id){
        boolean i=consumerService.removeById(id);
        if(i){
            return Result.ok();
        }else{
            return Result.error();
        }

    }

    @ApiOperation(value="修改需求方信息",notes = "修改需求方信息")
    @GetMapping("/updateConsumer")
    public Result updateConsumer(Consumer consumer){
        boolean i=consumerService.updateById(consumer);
        if(i){
            return Result.ok();
        }else{
            return Result.error();
        }

    }
}

